************************************************
*TABLE 2: Measures of defensive ownership, 2004
************************************************

*OLIGARCH AND DISTANCE
use "Regressions Data/baseline0406.dta",clear
keep if year==2004

tab shortest_path_oligarch
gen d1=1 if shortest_path_oligarch ==1
gen d2=1 if shortest_path_oligarch<=2
gen d3=1 if shortest_path_oligarch<=3
gen d4=1 if shortest_path_oligarch<=4
tempfile oligarch distance

preserve
collapse (count) okpo, by(no_oligarch_chain)
gen var="No oligarch in chain" if no_oligarch_chain==1
replace var="Oligarch in chain" if no_oligarch_chain==0
gen order=1 if no_oligarch_chain==1
replace order=2 if no_oligarch_chain==0
drop no_oligarch_chain
rename okpo Number
save `oligarch'

restore
drop if d4==.
collapse (count) okpo, by(d1 d2 d3 d4)
gen Number = sum(okpo)
gen var="Oligarch in chain, 1 step" if d1==1 & d2==1 & d3==1 & d4==1
replace var="Oligarch in chain, <=2 steps" if d1==. & d2==1 & d3==1 & d4==1
replace var="Oligarch in chain, <=3 steps" if d1==. & d2==. & d3==1 & d4==1
replace var="Oligarch in chain, <=4 steps" if d1==. & d2==. & d3==. & d4==1
drop d1 d2 d3 d4 okpo
gen order=3 if var=="Oligarch in chain, 1 step"
replace order=4 if var=="Oligarch in chain, <=2 steps"
replace order=5 if var=="Oligarch in chain, <=3 steps"
replace order=6 if var=="Oligarch in chain, <=4 steps"
save `distance'

*FOREIGN AND OFFSHORE
use "Regressions Data/baseline0406_nown.dta",clear
keep if year==2004
tempfile foreign
preserve
collapse (count) okpo, by(foreign_in_chain)
keep if foreign_in_chain==1
gen var="Foreign in chain"
rename okpo Number
drop foreign_in_chain
gen order=7
save `foreign'

restore
collapse (count) okpo, by(offshore)
keep if offshore==1
gen var="Offshore in chain"
rename okpo Number
drop offshore
gen order=8

append using `foreign'
append using `distance'
append using `oligarch'
sort order
gen Share= Number/329 if order<7
replace Share=Number/299 if order>=7
order var Share Number
drop order
tostring Share, replace force format(%9.3f)
export excel "Results/Table2.xls", firstrow (variables) replace


******************************************************************************************
*TABLE 3: Political connections and control variables
******************************************************************************************

*Panel A: Indicators
use "Regressions Data/baseline0406.dta",clear
keep if year==2004
tempfile color
preserve
collapse (count) okpo, by(color)
save `color'
restore 
keep if privatized==1
collapse (count) okpo, by(privatized)
append using `color'
replace color=4 if color==.
gen var="Blue" if color==1
replace var="Orange" if color==2
replace var="Gray" if color==3
replace var="Privatized" if color==4
sort color
drop color privatized
rename okpo Number
gen Share=Number/329
order var Share Number
tostring Share, replace force format(%9.3f)
export excel "Results/Table3_PanelA.xls", firstrow (variables) replace

*Panel B: Continious variables
use "Regressions Data/baseline0406.dta",clear
keep if year==2004
tempfile mean sd
preserve
collapse (mean)emp tfp YuDec
gen type=1
rename emp meanemp
rename tfp meantfp
rename YuDec meanyudec
reshape long mean, i(type) j(i) string
save `mean'
restore
collapse (sd) emp tfp YuDec
gen type=1
rename emp sdemp
rename tfp sdtfp
rename YuDec sdyudec
reshape long sd, i(type) j(i) string
merge 1:1 i using `mean'
drop type _merge
rename i var
replace var="Employment" if var=="emp"
replace var="TFP" if var=="tfp"
replace var="Vote for Yushchenko" if var=="yudec"
order var mean sd
rename mean Mean
rename sd SD
tostring Mean SD, replace force format(%9.2f)
export excel "Results/Table3_PanelB.xls", firstrow (variables) replace
